package com.itboye.ihomebank.activity.electric_meter;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;

/**
 * Created by Administrator on 2018/9/25 0025.
 */

public class IntroduceElecMeter extends BaseOtherActivity {
    //title
    RelativeLayout titlebar;
    ImageView close_icon;
    TextView add_shap_title_tv;

    ImageView callPhoneIv;
    View v_statusbar;
    PopupWindow callPop;

    TextView phoneTv,cancleTv,sureTv;
    ImageView pop_deleteIv;

    @Override
    protected int layout_id() {
        return R.layout.activity_introdce_elecmeter;
    }

    @Override
    protected void onInitController() {

    }

    @Override
    protected void onInit() {
        setStatusBarColor(getResources().getColor(R.color.introduce_elemeter));
        setStatusBarHeight(v_statusbar);
        titlebar.setBackgroundResource(R.color.introduce_elemeter);
        add_shap_title_tv.setText("智能电表");

//        showPop()
    }

    private void showPop() {


        View contentView = LayoutInflater.from(IntroduceElecMeter.this)
                .inflate(R.layout.popwind_introduce_callphone, null);

        phoneTv= (TextView) contentView.findViewById(R.id.phoneTv);
        cancleTv= (TextView) contentView.findViewById(R.id.cancleTv);
        sureTv= (TextView) contentView.findViewById(R.id.sureTv);
        pop_deleteIv= (ImageView) contentView.findViewById(R.id.pop_deleteIv);

        cancleTv.setOnClickListener(this);
        sureTv.setOnClickListener(this);
        pop_deleteIv.setOnClickListener(this);

        callPop=new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT,true);
        callPop.setAnimationStyle(R.style.popupwindow_anim_style);
        //passwordpop 可点击

        contentView.setFocusable(true);//comment by danielinbiti,设置view能够接听事件，标注1
        contentView.setFocusableInTouchMode(true); //comment by danielinbiti,设置view能够接听事件 标注2
        callPop.showAtLocation(contentView, Gravity.BOTTOM,0,0);

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.close_icon:
                this.finish();
                break;

            case R.id.callPhoneIv:
                //电话的popwindow
                showPop();
                break;

            case R.id.cancleTv: //点击取消
                callPop.dismiss();
                break;

            case R.id.pop_deleteIv: //关闭pop
                callPop.dismiss();
                break;

            case R.id.sureTv:// 确定呼叫
                 callPhone(phoneTv.getText().toString().trim());
                break;
        }
    }

    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        startActivity(intent);
    }
}
